<template>
  <!-- 展示数据表格 -->
  <div class="Lists">
    <el-table
      :data="menuListData"
      style="width: 100%; margin-bottom: 20px"
      row-key="id"
      border
      height="530"
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
    >
      <el-table-column prop="id" label="编号" sortable width="180">
      </el-table-column>
      <el-table-column prop="title" label="名称" sortable width="180">
      </el-table-column>
      <el-table-column prop="icon" label="图标">
        <template slot-scope="scope">
          <i :class="scope.row.icon"> </i>
        </template>
      </el-table-column>
      <el-table-column prop="url" label="地址"> </el-table-column>
      <el-table-column prop="status" label="状态">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.status == 1"
            >启用</el-tag
          >
          <el-tag v-if="scope.row.status == 2" type="danger" 
            >禁用</el-tag
          >
        </template>
      </el-table-column>
      <el-table-column prop="address" label="操作">
        <template slot-scope="scope">
          <el-button type="primary" @click="editMenu(scope.row.id)"
            >编辑</el-button
          >
          <el-button type="danger" @click="deleteMenu(scope.row.id)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { getMenuDelete } from "../../../request/api";
export default {
  props: ["menuListData"],
  data() {
    return {};
  },
  methods: {
    // 显示编辑对话框
    editMenu(id) {
      this.$emit("editMenu", id);
    },
    // 删除菜单
    deleteMenu(id) {
      this.$confirm("是否删除该菜单?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
      }).then(() => {
        getMenuDelete({ id }).then(
          (res) => {
            if (res.data.code == 200) {
              this.$message.success(`删除成功`);
              // 刷新删除后列表数据
              this.$emit("refreshDelList");
            }else{
              this.$message.warning(`${res.data.msg}`);
            }
          },
          (err) => err
        );
      },err=>err);
    },
  },
};
</script>

<style scoped>
</style>